Ext.BLANK_IMAGE_URL = '/static/images/common/s.gif';
// Ext.util.CSS.swapStyleSheet('theme','/static/js/ext/resources/css/xtheme-slate.css');

Ext.onReady(function() {
	var tbPanel = new Ext.TabPanel({
				region : 'center',
				deferredRender : false,
				activeTab : 0,
				items : [{
							contentEl : 'center',
							title : '首&nbsp;&nbsp;页',
							iconCls : 'icon-index',
							closable : false,
							autoScroll : true,
							id : 'node1'
						}]
			});

	var tb = new Ext.Toolbar('toolbar', {
				width : '100%'
			});

	tb.addElement('toptext');
	tb.addElement('space');

	tb.addSeparator();
	tb.addButton(new Ext.Button({
		text : '注销登录',
		iconCls : 'icon-logout',
		handler : function() {
			Ext.MessageBox.confirm('确认提示', '此操作将退出登陆，你将继续吗？', function(btn) {
				if (btn == "yes") {
					Ext.Ajax.request({
								url : '/login/logout.action',
								longdingText : '正在操作，请稍候……',
								success : function(response, options) {
									Ext.MessageBox.alert('提示', '您已经成功退出登陆。');
									window.location.href = '/login/agentLogin.action';
								},
								failure : function() {
									Ext.MessageBox.alert('提示',
											'对不起，删除操作失败，请检查网络。');
								}
							})
				}
			});
		}
	}));

	var root = new Ext.tree.TreeNode({
				text : '系统菜单'
			});

	var node1 = new Ext.tree.TreeNode({
				id : 'node1',
				leaf : true,
				iconCls : 'icon-index',
				text : '首&nbsp;&nbsp;页'
			});
	var node2 = new Ext.tree.TreeNode({
				id : 'node2',
				text : '客户管理'
			});
	var node3 = new Ext.tree.TreeNode({
				id : 'node3',
				text : '订单管理'
			});
	var node4 = new Ext.tree.TreeNode({
				id : 'node4',
				text : '用户管理',
				openUrl : '../agentUser/listAgentUser.action',
				leaf : true,
				iconCls : 'icon-user'
			});

	var node5 = new Ext.tree.TreeNode({
				id : 'node5',
				text : '拜访记录管理',
				openUrl : '../visitRecord/listAllVisitRecord.action',
				leaf : true
			});

	var node6 = new Ext.tree.TreeNode({
				id : 'node6',
				text : '售后服务管理',
				openUrl : '../serviceRecord/listAllServiceRecord.action',
				leaf : true
			});

	var node21 = new Ext.tree.TreeNode({
				id : 'node21',
				leaf : true,
				openUrl : '../customer/listFollowingCustomer.action',
				text : '跟进中客户',
				iconCls : 'icon-group'
			});
	var node22 = new Ext.tree.TreeNode({
				id : 'node22',
				leaf : true,
				openUrl : '../customer/listPayingCustomer.action',
				text : '付费客户',
				iconCls : 'icon-group'
			});

	var node31 = new Ext.tree.TreeNode({
				id : 'node31',
				leaf : true,
				openUrl : '../order/listAllOrder.action',
				text : '全部订单'
			});
	var node32 = new Ext.tree.TreeNode({
				id : 'node32',
				leaf : true,
				openUrl : '../order/listUncheckedOrder.action',
				text : '未审核订单'
			});
	var node33 = new Ext.tree.TreeNode({
				id : 'node133',
				leaf : true,
				openUrl : '../order/listOpenedOrder.action',
				text : '已开通订单'
			});

	root.appendChild(node1);
	root.appendChild(node2);
	root.appendChild(node3);
	root.appendChild(node5);
	root.appendChild(node6);
	root.appendChild(node4);

	node2.appendChild(node21);
	node2.appendChild(node22);

	node3.appendChild(node31);
	node3.appendChild(node32);
	node3.appendChild(node33);

	var tree = new Ext.tree.TreePanel({
				el : 'menuTree',
				animate : true,
				autoHeight : true,
				rootVisible : false
			});

	tree.setRootNode(root);
	tree.render();
	tree.expandAll();

	tree.on('dblclick', function(node, e) {
		if (node.leaf) {
			var html = '<iframe src="'
					+ node.attributes.openUrl
					+ '" frameborder=0 width=100% height=100% scrolling=auto></iframe>';
			var tab = tbPanel.items.get(node.id)
			if (tab == undefined)
				tab = tbPanel.add({
							id : node.id,
							title : node.text,
							html : html,
							closable : true,
							layout : 'fit',
							iconCls : node.attributes.iconCls
						});
			if (tbPanel != undefined || tbPanel != null)
				tbPanel.activate(tab);
		}
	});

	var viewport = new Ext.Viewport({
				layout : 'border',
				items : [new Ext.BoxComponent({
									region : 'north',
									el : 'north',
									tbar : tb
								}), new Ext.BoxComponent({
									region : 'south',
									el : 'south',
									margins : '0 0 0 5',
									height : 15
								}), {
							region : 'west',
							title : '菜单栏',
							split : true,
							width : 200,
							minSize : 175,
							maxSize : 400,
							collapsible : true,
							margins : '0 0 0 5',
							layout : 'accordion',
							layoutConfig : {
								animate : true
							},
							items : [{
										contentEl : 'west',
										title : '系统菜单',
										border : false,
										iconCls : 'icon-folder-wrench'
									}]
						}, tbPanel]
			});
	setTimeout(function() {
				Ext.get('loading').remove();
				Ext.get('loading-mask').fadeOut({
							remove : true
						});
			}, 300);
});
